package com.shenhaofeng.app.download;

import android.content.Context;

import com.shenhaofeng.app.exception.CreateFileException;

import java.io.File;


/**
 * Created by Administrator on 2016/9/14.
 */
 class Utils {


    public static  File returnOrCreateDir(File file) throws CreateFileException{
        if(file.exists()&&file.isDirectory()){
            return file;
        }else{
            boolean created=file.mkdirs();
            if(created){
                return file;
            }else{
                throw new CreateFileException(String.format("%s无法创建",file.getAbsoluteFile()));
            }
        }
    }


    /**
     * 获取默认的下载文件夹
     * @param context
     * @return
     */
    public static File getDefaultDownloadDir(Context context){
        File downloadDir=context.getExternalFilesDir("download");
        return downloadDir;
    }
}
